<?php


abstract class BaseSessionData extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $session_id = 'null';


	
	protected $http_user_agent = 'null';


	
	protected $session_data;


	
	protected $session_expire;


	
	protected $user_id;


	
	protected $username;


	
	protected $avatar_path;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getSessionId()
	{

		return $this->session_id;
	}

	
	public function getHttpUserAgent()
	{

		return $this->http_user_agent;
	}

	
	public function getSessionData()
	{

		return $this->session_data;
	}

	
	public function getSessionExpire($format = 'Y-m-d H:i:s')
	{

		if ($this->session_expire === null || $this->session_expire === '') {
			return null;
		} elseif (!is_int($this->session_expire)) {
						$ts = strtotime($this->session_expire);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [session_expire] as date/time value: " . var_export($this->session_expire, true));
			}
		} else {
			$ts = $this->session_expire;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getUsername()
	{

		return $this->username;
	}

	
	public function getAvatarPath()
	{

		return $this->avatar_path;
	}

	
	public function setSessionId($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->session_id !== $v || $v === 'null') {
			$this->session_id = $v;
			$this->modifiedColumns[] = SessionDataPeer::SESSION_ID;
		}

	} 
	
	public function setHttpUserAgent($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->http_user_agent !== $v || $v === 'null') {
			$this->http_user_agent = $v;
			$this->modifiedColumns[] = SessionDataPeer::HTTP_USER_AGENT;
		}

	} 
	
	public function setSessionData($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->session_data !== $v) {
			$this->session_data = $v;
			$this->modifiedColumns[] = SessionDataPeer::SESSION_DATA;
		}

	} 
	
	public function setSessionExpire($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [session_expire] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->session_expire !== $ts) {
			$this->session_expire = $ts;
			$this->modifiedColumns[] = SessionDataPeer::SESSION_EXPIRE;
		}

	} 
	
	public function setUserId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = SessionDataPeer::USER_ID;
		}

	} 
	
	public function setUsername($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->username !== $v) {
			$this->username = $v;
			$this->modifiedColumns[] = SessionDataPeer::USERNAME;
		}

	} 
	
	public function setAvatarPath($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->avatar_path !== $v) {
			$this->avatar_path = $v;
			$this->modifiedColumns[] = SessionDataPeer::AVATAR_PATH;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->session_id = $rs->getString($startcol + 0);

			$this->http_user_agent = $rs->getString($startcol + 1);

			$this->session_data = $rs->getString($startcol + 2);

			$this->session_expire = $rs->getTimestamp($startcol + 3, null);

			$this->user_id = $rs->getInt($startcol + 4);

			$this->username = $rs->getString($startcol + 5);

			$this->avatar_path = $rs->getString($startcol + 6);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 7; 
		} catch (Exception $e) {
			throw new PropelException("Error populating SessionData object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SessionDataPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			SessionDataPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SessionDataPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = SessionDataPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += SessionDataPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = SessionDataPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SessionDataPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getSessionId();
				break;
			case 1:
				return $this->getHttpUserAgent();
				break;
			case 2:
				return $this->getSessionData();
				break;
			case 3:
				return $this->getSessionExpire();
				break;
			case 4:
				return $this->getUserId();
				break;
			case 5:
				return $this->getUsername();
				break;
			case 6:
				return $this->getAvatarPath();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SessionDataPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getSessionId(),
			$keys[1] => $this->getHttpUserAgent(),
			$keys[2] => $this->getSessionData(),
			$keys[3] => $this->getSessionExpire(),
			$keys[4] => $this->getUserId(),
			$keys[5] => $this->getUsername(),
			$keys[6] => $this->getAvatarPath(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SessionDataPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setSessionId($value);
				break;
			case 1:
				$this->setHttpUserAgent($value);
				break;
			case 2:
				$this->setSessionData($value);
				break;
			case 3:
				$this->setSessionExpire($value);
				break;
			case 4:
				$this->setUserId($value);
				break;
			case 5:
				$this->setUsername($value);
				break;
			case 6:
				$this->setAvatarPath($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SessionDataPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setSessionId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setHttpUserAgent($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setSessionData($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setSessionExpire($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setUserId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setUsername($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setAvatarPath($arr[$keys[6]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(SessionDataPeer::DATABASE_NAME);

		if ($this->isColumnModified(SessionDataPeer::SESSION_ID)) $criteria->add(SessionDataPeer::SESSION_ID, $this->session_id);
		if ($this->isColumnModified(SessionDataPeer::HTTP_USER_AGENT)) $criteria->add(SessionDataPeer::HTTP_USER_AGENT, $this->http_user_agent);
		if ($this->isColumnModified(SessionDataPeer::SESSION_DATA)) $criteria->add(SessionDataPeer::SESSION_DATA, $this->session_data);
		if ($this->isColumnModified(SessionDataPeer::SESSION_EXPIRE)) $criteria->add(SessionDataPeer::SESSION_EXPIRE, $this->session_expire);
		if ($this->isColumnModified(SessionDataPeer::USER_ID)) $criteria->add(SessionDataPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(SessionDataPeer::USERNAME)) $criteria->add(SessionDataPeer::USERNAME, $this->username);
		if ($this->isColumnModified(SessionDataPeer::AVATAR_PATH)) $criteria->add(SessionDataPeer::AVATAR_PATH, $this->avatar_path);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(SessionDataPeer::DATABASE_NAME);

		$criteria->add(SessionDataPeer::SESSION_ID, $this->session_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getSessionId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setSessionId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setHttpUserAgent($this->http_user_agent);

		$copyObj->setSessionData($this->session_data);

		$copyObj->setSessionExpire($this->session_expire);

		$copyObj->setUserId($this->user_id);

		$copyObj->setUsername($this->username);

		$copyObj->setAvatarPath($this->avatar_path);


		$copyObj->setNew(true);

		$copyObj->setSessionId('null'); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new SessionDataPeer();
		}
		return self::$peer;
	}

} 